package cn.edu.neusoft.recyclerviewtest112gxl;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private Myadapter mAdapter;
    List<ArticleBean> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        getData();
    }
    private List<ArticleBean> getData() {
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        ArticleBean art;
        for (int i = 0; i < 6; i++) {
            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题"+i);
            art.setImgid(R.drawable.f1);
            art.setTime("2017-4-1 15:16");
            art.setDescription("描述"+i);
            list.add(art);
        }

        return list;
    }


    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);//创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(this);    //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);    //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);    //创建并设置Adapter
        list = getData();
        mAdapter = new Myadapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
    }
}
